package store

import "sync"

type BucketIndex struct {
	sync.RWMutex
	store map[uint64]uint64
}

func NewBucketIndex(size int) *BucketIndex {
	return &BucketIndex{
		store: make(map[uint64]uint64),
	}
}

func (i *BucketIndex) Update(hash uint64, last uint64) {
	i.Lock()
	i.store[hash] = last
	i.Unlock()
}

func (i *BucketIndex) Get(hash uint64) uint64 {
	i.RLock()
	if val, ok := i.store[hash]; ok {
		i.RUnlock()
		return val
	} else {
		i.RUnlock()
		return 0
	}
}
